'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('driverPref', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        carType:{
            type: Sequelize.STRING(10),
            allowNull: false,
        },
        securityFlag: {
            type: Sequelize.BOOLEAN,
        },
        greenFlag: {
            type: Sequelize.BOOLEAN,
        },
        roadFlag: {
            type: Sequelize.BOOLEAN,
        },
    }, {
        freezeTableName: true,
        tableName: 'tb_driver_pref',
        timestamps: true,
        paranoid: true,
    })

    Model.associate = function() {
        model.DriverPref.belongsTo(model.Corp)
        model.DriverPref.belongsTo(model.Driver)
        model.DriverPref.belongsTo(model.Sales)
        model.Corp.hasMany(model.DriverPref)
        model.Driver.hasMany(model.DriverPref)
        model.Sales.hasMany(model.DriverPref)
    }

    return Model
}